package com.lin.dao;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import com.lin.utils.JdbcUtils;
import com.lin.vo.Admin;

public class AdminDaoImpl implements IAdminDao {

    @Override
    public boolean login(Admin admin) {
        QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource());
        String sql = "SELECT count(1) FROM admin WHERE username = ? AND password = ?";
        Number number;
        try {
            number = (Number) queryRunner.query(sql, new ScalarHandler(), admin.getUsername(), admin.getPassword());
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException();
        }
        return number.intValue() > 0;
    }

}
